package com.example.ice.fittime.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.example.ice.fittime.entry.StickerImage;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "STICKER_IMAGE".
*/
public class StickerImageDao extends AbstractDao<StickerImage, String> {

    public static final String TABLENAME = "STICKER_IMAGE";

    /**
     * Properties of entity StickerImage.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Image_id = new Property(0, String.class, "image_id", true, "IMAGE_ID");
        public final static Property Content = new Property(1, String.class, "content", false, "CONTENT");
        public final static Property X = new Property(2, String.class, "x", false, "X");
        public final static Property Y = new Property(3, String.class, "y", false, "Y");
        public final static Property Style = new Property(4, String.class, "style", false, "STYLE");
        public final static Property Type = new Property(5, String.class, "type", false, "TYPE");
        public final static Property Sticker_s = new Property(6, String.class, "sticker_s", false, "STICKER_S");
    }

    private Query<StickerImage> userImage_StickerQuery;

    public StickerImageDao(DaoConfig config) {
        super(config);
    }
    
    public StickerImageDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"STICKER_IMAGE\" (" + //
                "\"IMAGE_ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: image_id
                "\"CONTENT\" TEXT," + // 1: content
                "\"X\" TEXT," + // 2: x
                "\"Y\" TEXT," + // 3: y
                "\"STYLE\" TEXT," + // 4: style
                "\"TYPE\" TEXT," + // 5: type
                "\"STICKER_S\" TEXT);"); // 6: sticker_s
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"STICKER_IMAGE\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, StickerImage entity) {
        stmt.clearBindings();
 
        String image_id = entity.getImage_id();
        if (image_id != null) {
            stmt.bindString(1, image_id);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(2, content);
        }
 
        String x = entity.getX();
        if (x != null) {
            stmt.bindString(3, x);
        }
 
        String y = entity.getY();
        if (y != null) {
            stmt.bindString(4, y);
        }
 
        String style = entity.getStyle();
        if (style != null) {
            stmt.bindString(5, style);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(6, type);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, StickerImage entity) {
        stmt.clearBindings();
 
        String image_id = entity.getImage_id();
        if (image_id != null) {
            stmt.bindString(1, image_id);
        }
 
        String content = entity.getContent();
        if (content != null) {
            stmt.bindString(2, content);
        }
 
        String x = entity.getX();
        if (x != null) {
            stmt.bindString(3, x);
        }
 
        String y = entity.getY();
        if (y != null) {
            stmt.bindString(4, y);
        }
 
        String style = entity.getStyle();
        if (style != null) {
            stmt.bindString(5, style);
        }
 
        String type = entity.getType();
        if (type != null) {
            stmt.bindString(6, type);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public StickerImage readEntity(Cursor cursor, int offset) {
        StickerImage entity = new StickerImage( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // image_id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // content
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // x
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // y
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // style
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // type
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, StickerImage entity, int offset) {
        entity.setImage_id(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setContent(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setX(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setY(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setStyle(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setType(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
     }
    
    @Override
    protected final String updateKeyAfterInsert(StickerImage entity, long rowId) {
        return entity.getImage_id();
    }
    
    @Override
    public String getKey(StickerImage entity) {
        if(entity != null) {
            return entity.getImage_id();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(StickerImage entity) {
        return entity.getImage_id() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "sticker" to-many relationship of UserImage. */
    public List<StickerImage> _queryUserImage_Sticker(String sticker_s) {
        synchronized (this) {
            if (userImage_StickerQuery == null) {
                QueryBuilder<StickerImage> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Sticker_s.eq(null));
                userImage_StickerQuery = queryBuilder.build();
            }
        }
        Query<StickerImage> query = userImage_StickerQuery.forCurrentThread();
        query.setParameter(0, sticker_s);
        return query.list();
    }

}
